<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>.::IFConnect::.</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="../styles/mainadmin.css" type="text/css" rel="stylesheet" media="all" />
    </h:head>

    <h:body>

        <div id="cabecalho">
            <a href="principalAdmin.xhtml" alt="Administração" title="Voltar a página principal de administração">
                <img src="../images/topadmin.png" width="700" height="100" alt="Área Administrativa" />
            </a>
            <br />
            <div id="logincontrol">
                <h:panelGrid columns="2">
                    <h:outputText value="Bem-vindo #{usuariologin.usuario.nome} #{usuariologin.usuario.sobrenome}  " />
                    <h:form>
                        <h:commandLink value="Logoff" action="#{usuariologin.logout()}"/>
                    </h:form>
                </h:panelGrid>

            </div>
        </div>

        <div id="estrutura">

            <div id="conteudo">
                <h2>Painel de Administração</h2>
                <h3>Cadastro de Diciplina</h3>

                <h:form id="cad">
                    <p:growl/>

                    <p:fieldset legend="Informações Gerais">
                        <h:panelGrid  columns="2">

                            <h:outputText value="*Nome:" />
                            <p:inputText label="Nome" required="true" value="#{disciplinaMB.disciplina.nome}" styleClass="campoTexto" />

                            <h:outputText value="*Curso:" />
                            <p:selectOneMenu id="curso" value="#{disciplinaMB.curso}" effect="fade">
                                <f:selectItem itemLabel="Selecione um Curso" noSelectionOption="true" />
                                <f:selectItems value="#{disciplinaMB.cursos}" var="selectCurso" itemLabel="#{selectCurso.nome}" itemValue="#{selectCurso}" />
                            </p:selectOneMenu>

                            <p:commandButton value="Salvar" update=":form, cad" action="#{disciplinaMB.addDisciplina()}" image="ui-icon ui-icon-disk"/>
                        </h:panelGrid>
                    </p:fieldset>
                </h:form> 

                <h3>Disciplinas cadastradas</h3>

                <h:form id="form">

                    <p:dataTable id="table-disciplinas" value="#{disciplinaMB.disciplinas}" var="disciplina" tableStyle="width:100%" paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15">

                        <p:column headerText="NOME">
                            <h:outputText value="#{disciplina.nome}" />
                        </p:column>

                        <p:column headerText="ALUNOS">  
                            <h:outputText value="#{disciplina.alunos.size()}" />  
                        </p:column>

                        <p:column headerText="CURSO">
                            <h:outputText value="#{disciplina.curso}" />  
                        </p:column>

                        <p:column style="width:40px">  
                            <p:commandButton id="selectButton" update=":form:display" oncomplete="disciplinaDialog.show()" icon="ui-icon-search" title="Ver">  
                                <f:setPropertyActionListener value="#{disciplina}" target="#{disciplinaMB.disciplinaSelecionada}" />  
                            </p:commandButton>  
                        </p:column>
                    </p:dataTable>

                    <p:dialog header="Detalhes da Disciplina" widgetVar="disciplinaDialog" resizable="false" id="disciplinaDlg" dynamic="true" 
                              showEffect="fade" hideEffect="explode" modal="true">  

                        <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">  

                            <h:outputText value="ID:" />  
                            <h:outputText value="#{disciplinaMB.disciplinaSelecionada.id}" style="font-weight:bold"/>  

                            <h:outputText value="NOME:" />  
                            <h:outputText value="#{disciplinaMB.disciplinaSelecionada.nome}" style="font-weight:bold"/>  

                            <h:outputText value="CURSO:" />  
                            <h:outputText value="#{disciplinaMB.disciplinaSelecionada.curso}" style="font-weight:bold"/>  

                            <h:outputText value="CAMPUS:" />  
                            <h:outputText value="#{disciplinaMB.disciplinaSelecionada.curso.campus.nome}" style="font-weight:bold"/>  

                            <h:outputText value="TOTAL DE ALUNOS:" />  
                            <h:outputText value="#{disciplinaMB.disciplinaSelecionada.alunos.size()}" style="font-weight:bold"/>  

                            <p:commandButton value="Excluir" onclick="confirmation.show()" icon="ui-icon-trash" type="button" />
                            <p:commandButton value="Atualizar" update=":cad" action="#{disciplinaMB.atualizaDisciplina()}" icon="ui-icon-refresh" oncomplete="disciplinaDialog.hide();" />


                        </h:panelGrid>  

                    </p:dialog>
                    <p:confirmDialog id="confirmDialog" message="Tem certeza que deseja excluir a Disciplina?" header="Excluir Disciplina" severity="alert" widgetVar="confirmation">  
                        <p:commandButton id="confirm" value="Confirmar" update=":form, :cad" oncomplete="confirmation.hide()" action="#{disciplinaMB.excluir()}" />  
                        <p:commandButton id="decline" value="Cancelar" onclick="confirmation.hide()" type="button" />   
                    </p:confirmDialog>
                </h:form>

            </div>

        </div>

    </h:body>
</html>